package top.jasonlam.car.exception;

import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import top.jasonlam.car.utils.Res;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@ControllerAdvice
public class GlobalExceptionHandler  {
    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    @ResponseBody
    public Res logicExceptionHandler(HttpServletRequest request, MethodArgumentNotValidException e, HttpServletResponse response) {

        return Res.builder().code(44033).message(e.getMessage()).build();
    }
}
